﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Asteroids
{
    public class Background 
    {
        private Texture2D backgroundTexture;
        private int screenheight, screenwidth;
        private Vector2 screenpos, origin, texturesize;
        public Vector2 backgroundPos = new Vector2(0, 0);
        public float scale = 1.0f;

        //public Background(Game g) : base(g) { }      
        //SpriteBatch spriteBatch;

        public void Load( GraphicsDevice device, Texture2D bTexture)
        {

            backgroundTexture = bTexture;
            screenheight = device.Viewport.Height;
            screenwidth = device.Viewport.Width;
            origin = new Vector2(backgroundTexture.Width / 2, 0);
            screenpos = new Vector2(screenwidth / 2, screenheight / 2);
            texturesize = new Vector2(0, backgroundTexture.Height);
            
        }

        public void Update(float deltaY)
        {
            screenpos.Y += deltaY;
            screenpos.Y = screenpos.Y % backgroundTexture.Height;
        }


        public void Draw(SpriteBatch batch)
        {
             if (screenpos.Y < screenheight)
            {
                
                batch.Draw(backgroundTexture, 
                                 screenpos, 
                                 null, 
                                 Color.White,
                                 0.0f, 
                                 origin, 
                                 1, 
                                 SpriteEffects.None,
                                 0);
                
             }

            
                batch.Draw(backgroundTexture, 
                                 screenpos - texturesize, 
                                 null, 
                                 Color.White,
                                 0.0f, 
                                 origin, 
                                 1, 
                                 SpriteEffects.None,
                                 0);
                
        }
         
    }
}
        